import Ember from 'ember';
import BaseBusiness from '../base-business';
import Pagination from '../pagination';

export default BaseBusiness.extend(Pagination,{
  header_title:'账户管理',
  model() {
    return {};
  },
  buildQueryParams() {
      var _self = this;
      var params = this.pagiParamsSet();
      var curController = this.getCurrentController();
      var filter = {};
      // var filter = {flagQueryType:'customerWithAccount'};
      var sort;
      if (curController) {
          if (curController.get('queryCondition')) {
              filter = $.extend({}, filter, {
                  '[bed][room][name@$like]@$or1': curController.get('queryCondition')
              });
              filter = $.extend({}, filter, {
                  '[bed][name@$like]@$or1': curController.get('queryCondition')
              });
              filter = $.extend({}, filter, {
                  'name@$like@$or1': curController.get('queryCondition')
              });
              filter = $.extend({}, filter, {
                  '[customerStatus][typecode@$like]@$or2---1': 'customerStatusIn'
              });
              filter = $.extend({}, filter, {
                  '[customerStatus][typecode@$like]@$or2---2': 'customerStatusTry'
              });
          } else {
              filter = $.extend({}, filter, {
                  '[customerStatus][typecode@$like]@$or1---1': 'customerStatusIn'
              });
              filter = $.extend({}, filter, {
                  '[customerStatus][typecode@$like]@$or1---2': 'customerStatusTry'
              });
          }
      }
      params.filter = filter;
      sort = {
          '[createTime]': 'desc',
      };
      params.sort = sort;
      console.log("params is:", params);
      return params;
  },
  doQuery: function() {
      var _self = this;
      var params = this.buildQueryParams(); //拼查询条件
      let customerList =   _self.findPaged('customer', params,function(customerList) {});
      _self.getCurrentController().set("customerList", customerList);
  },
  actions:{
    search:function(){
      this.doQuery();
    },
  },
  setupController: function(controller,model){
    var _self=this;
    var queryCondition = controller.get('input');
    controller.set('queryCondition', null);
    this.doQuery();
    this._super(controller,model);
  }
});
